[

// [this] used by array->each and map->each
define this => var('__this')
define this=(e) => { return $__this := #e }

/*
// [key] used by array (and staticarray) to denote ->get and ->find a key vs. ->get(position) and ->find(element)
define key => type {
    data private k
    public onCreate(k) => { .k = #k }
    public onCompare(k) => .k->onCompare(#k)
    public onCompare(p::pair) => .k->onCompare(#p->first)
    public asString() => string(.k)
    public onConvert() => .k
}
*/
/*
var('a') = array('a' = 1,'a')
$a->find('a') '<br>'
$a->find(key('a')) '<br>'
$a->get(1) '<br>'
$a->get(key('a')) '<br>'
*/


define encode_base64url(string::string)::string => #string->encodebase64url
define encode_base64url(string::bytes)::string => #string->encodebase64url

define decode_base64url(string::string)::string => #string->decodebase64url
define decode_base64url(string::bytes)::string => #string->decodebase64url

define unserialize(data::string) => serialization_reader(xml(#data))->read
define unserialize(data::bytes) => serialization_reader(xml(#data))->read

define carousel_count => type {
  data public index::integer=0, public minimum::integer=0, public maximum::integer=0, public by::integer=0 

  public onCreate(minimum::integer,maximum::integer,by::integer=-99999,index::integer=-99999) => {
    #index == -99999 ? .index = #minimum | .index = #index
    .minimum = #minimum
    .maximum = #maximum
    #by == -99999 ? (#minimum <= #maximum ? .by = 1 | .by = -1) | .by = #by
  }

  public next::integer => {
    !.index->between(.minimum,.maximum) ? .index = .minimum
    local(i) = .index
    .index += .by
    !.index->between(.minimum,.maximum) ? .index = .minimum
    return #i
  }

  public asString::string => {
    return .next->asString
  }

  public asInteger::integer => {
    return .next
  }
}
/*
var(a) = carousel_count(1,3)
loop(10)
$a
/loop
*/

define carousel => type {
  parent array
  data public index

  public onCreate(...) => {
    ..onCreate(:#rest)
    .index = carousel_count(1,#rest->size)
  }

  public asString => {
    .index->maximum = .size
    return .get(.index->asInteger)
  }

}
/*
var(c) = carousel('a','b','c')
loop(10)
$c
/loop

<table>
[loop(5)]
<tr style="color: [loop_count % 2 ? 'red' | 'yellow']"><td>hello</td></tr>
[/loop]
[var(zebra) = carousel('red','yellow')]
[loop(5)]
<tr style="color: [$zebra]"><td>hello</td></tr>
[/loop]
</table>

*/

define break() => fail(67348,'!break!');

define block() => {
	error_push;
	local(err_m = '', err_c = 0);
	protect => {
		handle => {
			#err_m = error_msg;
			#err_c = error_code;
		}
		givenblock();
	}
	error_pop;
	fail_if(#err_c && #err_c != 67348,#err_c,#err_m);
}

define repetition => type {
  public onCompare(rhs::integer)::integer => {
    return (loop_count % #rhs == 0 ? 0 | 1)
  }
  public onCompare(rhs::string)::integer => {
    return (loop_count % integer(#rhs) == 0 ? 0 | 1)
  }
}

define lp_header_nocache => {
  local(d) = date;
  #d->timezone = 'GMT';
  web_response->addHeader('Last-Modified' = #d->(format:'%a, %d %b %Y %H:%M:%S') + ' GMT');
  web_response->addHeader('Expires' = 'Thu, 11 Jun 1998 13:17:30 GMT');
  web_response->addHeader('Cache-Control' = 'no-store, no-cache, must-revalidate, no-transform, max-age=0, post-check=0, pre-check=0');
  web_response->addHeader('Pragma' = 'no-cache');

  if(!web_response->rawContent->contains('Vary:')); 
    web_response->addHeader('Vary' = '*');
  /if;
  if(!web_response->rawContent->contains('ETag:')); 
    web_response->addHeader('ETag' = '"'+Lasso_UniqueID+'"');
  /if;
}

]